package cn.iocoder.yudao.module.peizhen.controller.app.paitent;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;


import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;



import cn.iocoder.yudao.module.peizhen.controller.app.paitent.vo.*;
import cn.iocoder.yudao.module.peizhen.dal.dataobject.paitent.PaitentDO;
import cn.iocoder.yudao.module.peizhen.service.paitent.PaitentService;

@Tag(name = "用户 APP - 用户的陪诊病人")
@RestController
@RequestMapping("/peizhen/paitent")
@Validated
public class AppPaitentController {

    @Resource
    private PaitentService paitentService;

    @PostMapping("/create")
    @Operation(summary = "创建用户的陪诊病人")
    public CommonResult<Integer> createPaitent(@Valid @RequestBody AppPaitentSaveReqVO createReqVO) {
        return success(paitentService.createPaitent(createReqVO));
    }

    @PostMapping("/update")
    @Operation(summary = "更新用户的陪诊病人")
    public CommonResult<Boolean> updatePaitent(@Valid @RequestBody AppPaitentSaveReqVO updateReqVO) {
        paitentService.updatePaitent(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除用户的陪诊病人")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deletePaitent(@RequestParam("id") Integer id) {
        paitentService.deletePaitent(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得用户的陪诊病人")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<AppPaitentRespVO> getPaitent(@RequestParam("id") Long id) {
        PaitentDO paitent = paitentService.getPaitent(id);
        return success(BeanUtils.toBean(paitent, AppPaitentRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得用户的陪诊病人分页")
    public CommonResult<PageResult<AppPaitentRespVO>> getPaitentPage(@Valid AppPaitentPageReqVO pageReqVO) {
        PageResult<PaitentDO> pageResult = paitentService.getPaitentPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, AppPaitentRespVO.class));
    }


}